<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>秒杀测试</title>
    <script th:src="@{/js/jquery.min.js}"></script>
</head>
<body>
<button id="btn_secKill">秒杀商品</button>
<div id="count_num"></div>
<div id="result"></div>
<script type="text/javascript">
    var countNum = 0;
    $(function(){
        $("#btn_secKill").click(function(){
            var json={"code":"test1","num":1};
            for(var i = 0 ; i < 20 ; i++){
                $.post("secKill",json,function(data){
                    // if(data != "排队人数太多，请稍后再试."){
                    //     $("#result").append("<br />" + data + i+"<br />");
                    // }else{
                    //     $("#result").append("<br />" + data + i+"<br />");
                    // }
                    $("#result").append("<br />" + data +"<br />");
                    if(data.indexOf("恭喜您，购买成功") != -1){
                        countNum ++;
                    }
                    $("#count_num").text("总共卖出："+countNum);
                });
            }
        });
    });
</script>
</body>
</html>
